import os

import requests
import time
def getScanResult(**kwargs):


    cookies = {
        'JSESSIONID': kwargs.get('JSESSIONID'),
        'tempTokenKey': kwargs.get('tempTokenKey'),
    }

    headers = {
        'Host': 'gzmh.zwfw.guizhou.gov.cn',
        'sec-ch-ua-platform': '"Windows"',
        'X-Requested-With': 'XMLHttpRequest',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36 Edg/137.0.0.0',
        'Accept': 'application/json, text/javascript, */*; q=0.01',
        'sec-ch-ua': '"Microsoft Edge";v="137", "Chromium";v="137", "Not/A)Brand";v="24"',
        'sec-ch-ua-mobile': '?0',
        'Sec-Fetch-Site': 'same-origin',
        'Sec-Fetch-Mode': 'cors',
        'Sec-Fetch-Dest': 'empty',
        'Referer': 'https://gzmh.zwfw.guizhou.gov.cn/ucenter/simpleLogin?=&response_type=code&client_id=dgov-portal&redirect_uri=https://gzmh.zwfw.guizhou.gov.cn/login/callback.html&version=guizhou&isHLW=true',
        'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
    }

    params = {
        'UnKey': kwargs.get('UnKey'),
        'isHLW': 'true',
        'csrf': kwargs.get('csrf'),
        'client_id': 'dgov-portal',
        'redirect_uri': 'https://gzmh.zwfw.guizhou.gov.cn/login/callback.html',
        'response_type': 'code',
        'scope': 'read',
        'state': kwargs.get('state'),
        'busi_uri': '',
        'is_weak_pwd': '0',
        'username': kwargs.get('username'),
        'password': kwargs.get('password'),
        'captcha': kwargs.get('captcha'),
        '_': int(time.time() * 1000),
    }


    for i in range(60):
        time.sleep(2)
        response = requests.get(
            'https://gzmh.zwfw.guizhou.gov.cn/ucenter/web/guizhou/getScanResult',
            params=params,
            cookies=cookies,
            headers=headers,
        )
        # print(f"\033[91m{response.json()}\033[0m")
        if response.json()['state']=='200':

            print(f"\033[92m{response.json()}\033[0m")




            break
